package com.aboat.view.panel;

import com.aboat.action.AddPlusRegularListener;
import com.aboat.action.DelPlusRegularListener;
import com.aboat.view.WindowFrame;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;

/**
 * 正则表达式添加面板
 *
 * @author aboat
 * @email clear_windy@yeah.net
 * @create 2017-04-09 12:58
 */
public class PlusRegularPanel extends JPanel {
    public PlusRegularPanel(){
        setPreferredSize(new Dimension(320,220));
        setLayout(new FlowLayout(FlowLayout.LEFT));
        this.setBorder(BorderFactory.createLineBorder(Color.gray,0));

        JLabel plusRegularLabel = new JLabel("允许正则:");
        JTextField plusRegularField = new JTextField("",27);
        JButton addPlusRegularButton = new JButton("+");
        JButton delPlusRegularButton = new JButton("-");

        this.add(plusRegularLabel);
        this.add(plusRegularField);
        this.add(addPlusRegularButton);
        this.add(delPlusRegularButton);


        String[] columnNames = {"允许正则列表"};   //列名
        String[][] tableVales={}; //数据
        WindowFrame.splusRegularTableModel = new DefaultTableModel(tableVales,columnNames);
        JTable table = new JTable(WindowFrame.splusRegularTableModel);
        addPlusRegularButton.addActionListener(new AddPlusRegularListener(WindowFrame.splusRegularTableModel,plusRegularField));
        delPlusRegularButton.addActionListener(new DelPlusRegularListener(WindowFrame.splusRegularTableModel,table));
        table.setPreferredScrollableViewportSize(new Dimension(285, 120));
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane scrollpane = new JScrollPane(table);
        this.add(scrollpane);

    }
}
